<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%--引用标签--%>
<%@ include file="/WEB-INF/include/taglib.jsp"%>
<%@ include file="/WEB-INF/include/head.basic.jsp"%>
<%@ include file="/WEB-INF/include/head.ueditor.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>创建采购单</title>
<script type="text/javascript" src="<c:url value='/js/jquery-form.js'/>"></script>
<script type="text/javascript">
	$(function(){
		Bean.init();
	});
	//表单提交
	function forSave(type) {
		$('#purchaseDetailInfos').val(Bean.forGetpurchaseDetail());
		//使按钮失效防止重复提交
		$("#saveBtn").linkbutton("disable");
		if(type==0){
			$("#saveForm").attr("action","savePurchaseOrder");
		}else if(type==2){
			$('#auditOrderId').val($('#purchaseOrderId').val());
			$('#auditType').val($('#taskDefinitionKey').val());
			$('#auditStatus').val("1");
			$("#saveForm").attr("action","submitPurchaseOrderAudit");
		}else if(type==3){
			$('#auditOrderId').val($('#purchaseOrderId').val());
			$('#auditType').val($('#taskDefinitionKey').val());
			$('#auditStatus').val("0");
			$("#saveForm").attr("action","submitPurchaseOrderAudit");
		}
		$("#saveForm").submit();
	}
	
</script>
</head>
<body>
<div id="panel">
	<form:form method="post" modelAttribute="purchaseOrderVo" id="saveForm">
		<div class="easyui-tabs"  id="ttTab" align="center">
			<div title="基本信息" style="padding: 10px">
					<input type="hidden" id="purchaseDetailInfos" name="purchaseDetailInfos" value="${purchaseDetailInfos}"/>
					<form:hidden path="purchaseOrderWithProcess.taskId" id="taskId"/>
					<form:hidden path="purchaseOrderWithProcess.taskName" id="taskName"/>
					<form:hidden path="purchaseOrderWithProcess.taskDefinitionKey" id="taskDefinitionKey"/>
					<table align="center" cellpadding="10px" style="border-spacing: 0;">
						<tr>
							<td>采购单号：</td>
							<td><form:input path="purchaseOrderWithProcess.id" id="purchaseOrderId" cssClass="easyui-textbox" data-options="editable:false"/></td>
							<td>采购单名称：</td>
							<td><form:input path="purchaseOrderWithProcess.title" cssClass="easyui-textbox"/></td>
							<td>紧急程度：</td>
							<td>
								<form:select path="purchaseOrderWithProcess.level"  cssClass="easyui-combobox" cssStyle="width:170px" data-options="editable:false">
				                           <form:option value="3">普通</form:option>
				                           <form:option value="2">二级</form:option>
				                           <form:option value="1">一级</form:option>
				                   </form:select>
							</td>
						</tr>
						<tr>
							<td>部门：</td>
							<td><form:input path="purchaseOrderWithProcess.department" cssClass="easyui-textbox"/></td>
							<td>采购人：</td>
							<td><form:input path="purchaseOrderWithProcess.createUser" cssClass="easyui-textbox"/></td>
							<td>总预算：</td>
							<td><form:input path="purchaseOrderWithProcess.budget" cssClass="easyui-textbox"/></td>
						</tr>
						<tr>
							<td>备注：</td>
							<td colspan="5"><form:input  path="purchaseOrderWithProcess.remark"  cssClass="easyui-textbox" data-options="multiline:true" cssStyle="height:70px;width:400px;"></form:input></td>
						</tr>
						<tr>
							<td colspan="6">
								<!--表格工具栏-->
								<div id="tool" style="padding:5px;height:auto">
									<table>
										<tr>
											<td><a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="Bean.addRow();">增加采购明细</a></td>
											<td><a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="Bean.removeRow();">删除采购明细</a></td>
										</tr>
									</table>
								</div>
								<!--选择的协议表格-->
								<table class="easyui-datagrid" data-options="width:800,toolbar:'#tool'" id="purchaseDetail" align="center">
									<thead>
										<tr>
											<th data-options="field:'ck',checkbox:true"></th>
											<th data-options="field:'codeTitle',editor:'textbox'" width="15%">采购名称</th>
											<th data-options="field:'codeSize',editor:'textbox'" width="15%">规格</th>
											<th data-options="field:'codeUnit',editor:'textbox'" width="15%">单位</th>
											<th data-options="field:'codeQuantity',editor:'textbox'" width="15%">数量</th>
											<th data-options="field:'codePrice',editor:'textbox'" width="15%">单价</th>
											<th data-options="field:'codeDescription',editor:'textbox'" width="15%">商品描述</th>
										</tr>
									</thead>
									<tbody>
											<c:forEach items="${purchaseOrderVo.purchaseOrderWithProcess.purchaseOrderDetails}" var="bind">
												<tr>
													<td>${bind.id}</td>
													<td>${bind.name}</td>
													<td>${bind.size}</td>
													<td>${bind.unit}</td>
													<td>${bind.quantity}</td>
													<td>${bind.price}</td>
													<td>${bind.description}</td>
												</tr>
											</c:forEach>
									</tbody>
								</table>
							</td>
						</tr>
					</table>
			</div>
			<div title="审核信息" style="padding: 10px">
				<table align="center" cellpadding="10px" style="border-spacing: 0;">
						<tr>
							<td>审核意见：</td>
							<td><form:input  path="purchaseOrderAudit.auditInfo"  cssClass="easyui-textbox" data-options="multiline:true" cssStyle="height:70px;width:400px;"></form:input></td>
							<td>
								<form:hidden path="purchaseOrderAudit.orderId" id="auditOrderId"/>
								<form:hidden path="purchaseOrderAudit.auditType" id="auditType"/>
								<form:hidden path="purchaseOrderAudit.status" id="auditStatus"/>
							</td>
						</tr>
				</table>
			</div>
		</div>
	</form:form>
</div>
<div id="foot" style="padding:5px;text-align:center ; ">
	<c:if test="${operate!='look' && (purchaseOrderVo.purchaseOrderWithProcess==null || purchaseOrderVo.purchaseOrderWithProcess.status==null || purchaseOrderVo.purchaseOrderWithProcess.status=='')}">
		<a href="###" id="saveBtn" class="easyui-linkbutton" iconCls="icon-save" onclick="forSave(0);" >保存数据</a>
	</c:if>
	<%-- <c:if test="${purchaseOrderVo.purchaseOrderWithProcess!=null && purchaseOrderVo.purchaseOrderWithProcess.id!=null && purchaseOrderVo.purchaseOrderWithProcess.id!='' && (purchaseOrderVo.purchaseOrderWithProcess.taskId==null || purchaseOrderVo.purchaseOrderWithProcess.taskId=='')}">
		<a href="###" id="saveBtn" class="easyui-linkbutton" iconCls="icon-save" onclick="forSave(1);" >提交并开始流程</a>
	</c:if> --%>
	<c:if test="${operate!='look' && (purchaseOrderVo.purchaseOrderWithProcess!=null && purchaseOrderVo.purchaseOrderWithProcess.taskId!=null && purchaseOrderVo.purchaseOrderWithProcess.taskId!='')}">
		<a href="###" id="saveBtn" class="easyui-linkbutton" iconCls="icon-save" onclick="forSave(2);" >通过</a>
		<a href="###" id="saveBtn" class="easyui-linkbutton" iconCls="icon-save" onclick="forSave(3);" >不通过</a>
	</c:if>
</div>
</body>
<script type="application/javascript">
	var Bean={
		options : {
			title : $('#purchaseOrderId').val()!=null && $('#purchaseOrderId').val() !='' ? $('#taskId').val!=null && $('#taskId')!='' ? '采购单审核' : '确认采购单':'创建采购单',
			fit : false,
			iconCls:null,
			footer : "#foot",
			headerCls : "titleCss"
		},
		init:function(){
			$("#panel").panel(this.options);//设置Panel信息
			var currentRows = $("#purchaseDetail").datagrid("getRows");
			if(currentRows.length>0){
				$.each(currentRows,function(currentIndex,element){
					$('#purchaseDetail').datagrid('beginEdit',currentIndex);
				});
			}
			if('${purchaseOrderVo.purchaseOrderWithProcess.taskId}'==null || '${purchaseOrderVo.purchaseOrderWithProcess.taskId}'==''){
				$('#ttTab').tabs('getTab', "审核信息").panel('options').tab.hide();
			}
		},
		addRow:function(){
			//添加一行协议
			var index=$('#purchaseDetail').datagrid('appendRow', {
						codeTitle: '',
						codeSize: '',
						codeUnit:'',
						codeQuantity:'',
						codePrice:0,
						codeDescription:''
					});
			$('#purchaseDetail').datagrid('beginEdit',0);
			$('#purchaseDetail').datagrid('beginEdit',1);
			$('#purchaseDetail').datagrid('beginEdit',2);
			$('#purchaseDetail').datagrid('beginEdit',3);
			$('#purchaseDetail').datagrid('beginEdit',4);
			$('#purchaseDetail').datagrid('beginEdit',5);
		},
		removeRow : function(){
			//删除选中的已添加的协议行
			var selected = $('#purchaseDetail').datagrid('getSelections');
			for(var i=0;i<selected.length;i++){
				var index = $('#purchaseDetail').datagrid('getRowIndex', selected[i]);
				$('#purchaseDetail').datagrid('deleteRow', index);
			}
		},
		forGetpurchaseDetail : function(){
			//供父窗口调用
			$('#purchaseDetail').datagrid('acceptChanges');
			var detail="";
			var currentRows = $("#purchaseDetail").datagrid("getRows");
			if(currentRows.length>0){
				$.each(currentRows,function(currentIndex,element){
					detail += element.codeTitle+'!'+element.codeSize+'!'+element.codeUnit+"!"+element.codeQuantity+"!"+element.codePrice+"!"+element.codeDescription+"!"+",";
				});
			}
			return detail;
		}
	};
</script>
</html>